﻿using System;
using System.Collections.Generic;
using System.Linq;
using Apps.Models;
using Apps.Common;
using Microsoft.Practices.Unity;
using System.Transactions;
using Apps.BLL.Core;
using Apps.Locale;
using LinqToExcel;
using System.IO;
using System.Text;
using System.Linq.Expressions;
using Apps.IDAL.PL;
using Apps.Models.PL;
using Apps.IBLL.PL;
namespace Apps.BLL.PL
{
    public partial class V_PL_BATCH_FOR_TESTBLL
    {
        DBContainer db = new DBContainer();
        public List<V_PL_BATCH_FOR_TEST> GetPagerListnew(ref GridPager pager, Expression<Func<V_PL_BATCH_FOR_TEST, bool>> whereLambda)
        {
            IQueryable<V_PL_BATCH_FOR_TEST> queryData = this.db.V_PL_BATCH_FOR_TEST.AsQueryable<V_PL_BATCH_FOR_TEST>();

            queryData = queryData.Where(whereLambda.Compile()).AsQueryable();
            pager.totalRows = queryData.Count();
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            //排序
            return queryData.ToList();
        }
        public List<V_PL_BATCH_FOR_TESTModel> GetList(ref GridPager pager, string sDate, string eDate, string queryStrBATCH_CODE, string queryStrARTIFICIAL_CODE, string queryStrTEST_CODE)
        {
            IQueryable<V_PL_BATCH_FOR_TEST> queryData = this.db.V_PL_BATCH_FOR_TEST.AsQueryable<V_PL_BATCH_FOR_TEST>();
            if (!string.IsNullOrWhiteSpace(queryStrBATCH_CODE))
            {
                queryData = queryData.Where(m => m.BATCH_CODE.Contains(queryStrBATCH_CODE));
            }
             if (!string.IsNullOrWhiteSpace(queryStrARTIFICIAL_CODE))
            {
                queryData = queryData.Where(m => m.ARTIFICIAL_CODE.ToString().Contains(queryStrARTIFICIAL_CODE));
            }
             if (!string.IsNullOrWhiteSpace(queryStrTEST_CODE))
            {
                    queryData = queryData.Where(m => m.TEST_CODE.Contains(queryStrTEST_CODE));
            }
             if (!string.IsNullOrEmpty(sDate))
            {
                DateTime dStartDate = DateTime.ParseExact(sDate, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.PLAN_DATE >= dStartDate);
            }
             if (!string.IsNullOrEmpty(eDate))
            {
                DateTime dEndDate = DateTime.ParseExact(eDate, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.PLAN_DATE < dEndDate);
            }

            if(string.IsNullOrWhiteSpace(queryStrBATCH_CODE)&& string.IsNullOrWhiteSpace(queryStrTEST_CODE)&& string.IsNullOrWhiteSpace(queryStrARTIFICIAL_CODE)&& string.IsNullOrEmpty(sDate)&& string.IsNullOrEmpty(eDate))
            {
                queryData = m_Rep.GetList();
            }
            pager.totalRows = queryData.Count();
            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return CreateModelLists(ref queryData);
        }
        public List<V_PL_BATCH_FOR_TESTModel> CreateModelLists(ref IQueryable<V_PL_BATCH_FOR_TEST> queryData)
        {
            List<V_PL_BATCH_FOR_TESTModel> modelList = (from r in queryData
                                                        select new V_PL_BATCH_FOR_TESTModel
                                                        {
                                                            PLAN_DATE = r.PLAN_DATE,
                                                            BATCH_CODE = r.BATCH_CODE,
                                                            ARTIFICIAL_CODE = r.ARTIFICIAL_CODE,
                                                            TEST_CODE = r.TEST_CODE,
                                                            MINE_ID = r.MINE_ID,
                                                            MINE_NAME = r.MINE_NAME,
                                                            MATERIEL_ID = r.MATERIEL_ID,
                                                            MATERIEL_NAME = r.MATERIEL_NAME,
                                                            STATISTICS = r.STATISTICS,
                                                            SUPPLIER_ID = r.SUPPLIER_ID,
                                                            SUPPLIER_NAME = r.SUPPLIER_NAME,
                                                            TRANSPORT_ID = r.TRANSPORT_ID,
                                                            TRANSPORT_NAME = r.TRANSPORT_NAME,
                                                            BEGIN_TIME = r.BEGIN_TIME,
                                                            END_TIME = r.END_TIME,
                                                            AMOUNT = r.AMOUNT,
                                                            QNET = r.QNET,
                                                            ST = r.ST,
                                                            REMARKS = r.REMARKS,
                                                          MAKE_CODE=r.MAKE_CODE,
                                                          MAKE_MODE_STR=r.MAKE_MODE_STR,
                                                          EQUIPMENT_NAME=r.EQUIPMENT_NAME
                                                        }).ToList();
        
        return modelList;
        }
         
    }
}
